package com.hskn.hss.module.empPlan.vo;

import com.hskn.hss.module.alarmperson.entity.AlarmPerson;
import com.hskn.hss.module.depart.entity.SysDepart;
import com.hskn.hss.module.dlbjviolation.entity.DlbjViolation;
import com.hskn.hss.module.rptEmployeeWork.entity.RptEmployeeWork;
import com.hskn.hss.module.tlemployee.entity.TlEmployee;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.*;

/**
 * 作业计划汇总报表TO
 *
 * @author zcy
 * @date 2021/10/9 13:21

 */
@Data
@ApiModel(value = "作业计划汇总明细报表列表-VO", description = "作业计划汇总明细报表列表-VO")
public class EmpPlanSummaryDetailTableVO implements Serializable {
    @ApiModelProperty(value = "机构名称", name = "depName")
    private String depName;
    @ApiModelProperty(value = "网格名称", name = "gridName")
    private String gridName;
    @ApiModelProperty(value = "计划名称", name = "planName")
    private String planName;
    @ApiModelProperty(value = "作业开始时间", name = "startDate")
    private Date startDate;
    @ApiModelProperty(value = "作业完成时间", name = "endDate")
    private Date endDate;
    @ApiModelProperty(value = "完成人", name = "overPersonName")
    private String overPersonName;
    @ApiModelProperty(value = "作业时长", name = "workTimeLength")
    private String workTimeLength;
    @ApiModelProperty(value = "报警次数", name = "alarmCounts")
    private Integer alarmCounts;
    @ApiModelProperty(value = "违规次数", name = "violationCounts")
    private Integer violationCounts;

    public static EmpPlanSummaryDetailTableVO buildEmpPlanSummaryDetailTableVO(
            RptEmployeeWork rptEmployeeWork , Map<String, TlEmployee> employeeMap, Map<String, SysDepart> departMap,
            Map<String, List<AlarmPerson>> alarmMap, Map<String, List<DlbjViolation>> dlbjViolationMap) {
        EmpPlanSummaryDetailTableVO empPlanSummaryTableVO = new EmpPlanSummaryDetailTableVO();
        String depName = "";
        String gridName = rptEmployeeWork.getGridName();
        String planName = rptEmployeeWork.getPlanName();
        Date startDate = rptEmployeeWork.getWorkStartTime();
        Date endDate = rptEmployeeWork.getWorkEndTime();
        String overPersonName = "";
        if (employeeMap.containsKey(rptEmployeeWork.getEmployeeId())) {
            overPersonName = employeeMap.get(rptEmployeeWork.getEmployeeId()).getName();
        }
        String workTimeLength = "";
        if (Objects.nonNull(rptEmployeeWork.getWorkStartTime())&&Objects.nonNull(rptEmployeeWork.getWorkEndTime())) {
            workTimeLength = Tools.secondToTime(rptEmployeeWork.getWorkEndTime().getTime()-rptEmployeeWork.getWorkStartTime().getTime());
        }
        Integer alarmCounts = 0;
        Integer violationCounts = 0;
        if (employeeMap.containsKey(rptEmployeeWork.getEmployeeId())&&departMap.containsKey(employeeMap.get(rptEmployeeWork.getEmployeeId()).getEmpldeptid())) {
            depName=departMap.get(employeeMap.get(rptEmployeeWork.getEmployeeId()).getEmpldeptid()).getDepartName();
        }
        if (alarmMap.containsKey(rptEmployeeWork.getGridId())) {
            alarmCounts = alarmMap.get(rptEmployeeWork.getGridId()).size();
        }
        if (dlbjViolationMap.containsKey(rptEmployeeWork.getGridId())) {
            violationCounts = dlbjViolationMap.get(rptEmployeeWork.getGridId()).size();
        }
        empPlanSummaryTableVO.setDepName(depName);
        empPlanSummaryTableVO.setGridName(gridName);
        empPlanSummaryTableVO.setPlanName(planName);
        empPlanSummaryTableVO.setStartDate(startDate);
        empPlanSummaryTableVO.setEndDate(endDate);
        empPlanSummaryTableVO.setOverPersonName(overPersonName);
        empPlanSummaryTableVO.setWorkTimeLength(workTimeLength);
        empPlanSummaryTableVO.setAlarmCounts(alarmCounts);
        empPlanSummaryTableVO.setViolationCounts(violationCounts);
        return empPlanSummaryTableVO;
    }
}
